﻿#ifndef UUID32_H_INCLUDED
#define UUID32_H_INCLUDED

#include <stdlib.h>
#include <assert.h>
#include <memory.h>
#include <stdint.h>
#include <string>
#include "SLT_tool_pub_def.h"

struct slt_uuid_t
{
	unsigned int    data1;
	unsigned short    data2;
	unsigned short    data3;
	unsigned char    data4[8];

	slt_uuid_t() {}
	slt_uuid_t(const slt_uuid_t& p) {
		memcpy(this, &p, sizeof(slt_uuid_t));
	}
	bool operator<(const slt_uuid_t& p) const //支持作为mapkey
	{
		if (memcmp(this, &p, sizeof(slt_uuid_t)) < 0) {
			return true;
		}
		return false;
	}
	bool operator==(const slt_uuid_t& p) const
	{
		return (memcmp(this, &p, sizeof(slt_uuid_t)) == 0) ? true : false;
	}
	bool operator!=(const slt_uuid_t& p) const
	{
		return (memcmp(this, &p, sizeof(slt_uuid_t)) != 0) ? true : false;
	}
	/*slt_uuid_t& operator = (const slt_uuid_t& p) {
		if (this == &p) {
			return *this;
		}
		memcpy(this, &p, sizeof(slt_uuid_t));
		return *this;
	}*/
};

/**
 * Generates a new UUID. The UUID is a time-based time 1 UUID.
 * A random per-process node identifier is used to avoid keeping global
 * state and maintaining inter-process synchronization.
 **/
SLT_API void slt_uuid_create(slt_uuid_t* uuid);

/**
 * Translate a uuid_t to a uuid string. len 37Byte
 *  return UUID string
 **/
SLT_API void slt_uuid_to_string(const slt_uuid_t* uuid,char *oBuf,int inBufLen);
SLT_API std::string slt_uuid_to_string(const slt_uuid_t* uuid);
/**
 * Compare two UUID's lexically
 *    return
 *      -1   u1 is lexically before u2
 *     0   u1 is equal to u2
 *     1   u1 is lexically after u2
*/
SLT_API int slt_uuid_compare(const slt_uuid_t *u1, const slt_uuid_t *u2);

#endif        /* UUID32_H_INCLUDED */